﻿using System;
using System.Collections.Generic;
using System.Linq;
using good1.Core;
using good1.Core.Interfaces.Data;
using SharpArch.Data.NHibernate;
using good1.Data.Extensions;

namespace good1.Data.Repositories
{
    public class ProjectRepository : Repository<Project>, IProjectRepository
    {
        public IList<Project> GetAllSorted()
        {
            return GetAll().AsQueryable().OrderBy(i => i.Priority).ToList();
        }

        public IList<Project> GetPage(int start, int max)
        {
            return GetAll().AsQueryable().OrderBy(i => i.Priority).Skip(start).Take(max).ToList();
        }

        public IList<Project> Search(string query, int start, int max)
        {
            IQueryable<Project> projects = GetAll().AsQueryable();
            projects = projects.Where(i => i.Text.Contains(query, StringComparison.InvariantCultureIgnoreCase) || i.Title.Contains(query, StringComparison.InvariantCultureIgnoreCase));
            return projects.OrderBy(i => i.Priority).ToList();
        }
    }
}
